﻿using DevExpressWebApplication1.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DevExpressWebApplication1.Module.MM
{
    public partial class StockType : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void gvStockType_CustomCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e)
        {
            int sttId = int.Parse(hdfStockType.Get("StockTypeId").ToString());
            if (sttId > 0)
            {
                try
                {
                    StockUtils.StockTypeUpdate(sttId, txtStockType.Text, txtDescription.Text);

                    gvStockType.DataBind();
                }
                catch (Exception ex)
                {
                    Console.Write("Update stock type fails : " + ex.Message);
                }
            }
            else
            {
                try
                {
                    StockUtils.StockTypeInsert(txtStockType.Text, txtDescription.Text);
                    gvStockType.DataBind();
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                }
            }
        }

        protected void cbAddEdit_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
        {
            string[] split = e.Parameter.Split(';');
            if (split[0] == "Edit")
            {
                txtStockType.Text = gvStockType.GetRowValues(int.Parse(split[1].ToString()), "stock_type_name").ToString();
                txtDescription.Text = gvStockType.GetRowValues(int.Parse(split[1].ToString()), "description").ToString();
                hdfStockType.Set("StockTypeId", gvStockType.GetRowValues(int.Parse(split[1].ToString()), "stock_type_id").ToString());
            }
        }
    }
}